package com.socool.sinofaith;

import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationManager;
import android.provider.Settings;

public class S {
	public static void checkGPS(final Context context) {
		LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
		boolean isOpen = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
		if (!isOpen) {
			new AlertDialog.Builder(context).setMessage("检测到GPS未开启")
					.setNeutralButton("去开启", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							dialog.cancel();
							Intent intent = new Intent();
							intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
							intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
							try {
								context.startActivity(intent);
							} catch (ActivityNotFoundException ex) {
								intent.setAction(Settings.ACTION_SETTINGS);
								try {
									context.startActivity(intent);
								} catch (Exception e) {
								}
							}
						}
					}).setCancelable(false).show();
		}
	}
}
